package com.nbsaas.boot.product.rest.convert;

import com.nbsaas.boot.product.data.entity.Product;
import com.nbsaas.boot.product.api.domain.response.ProductResponse;

import com.nbsaas.boot.utils.BeanDataUtils;
import com.nbsaas.boot.rest.api.Converter;
import java.util.HashMap;
import java.util.Map;
/**
* 商品-实体对象转化成响应对象
*/

public class ProductResponseConvert  implements Converter<ProductResponse,Product> {

    @Override
    public ProductResponse convert(Product source) {
        ProductResponse  result = new  ProductResponse();
        BeanDataUtils.copyProperties(source, result);
                    if(source.getShop()!=null){
                        result.setShop(source.getShop().getId());
                    }

                    try {
                        if(source.getShop()!=null){
                            result.setShopName(source.getShop().getName());
                        }
                    } catch (Exception ignored) { }


                    try {
                        if(source.getProductGroup()!=null){
                            result.setProductGroupName(source.getProductGroup().getName());
                        }
                    } catch (Exception ignored) { }

                    if(source.getProductGroup()!=null){
                        result.setProductGroup(source.getProductGroup().getId());
                    }
                    if(source.getStoreState()!=null){
                        result.setStoreStateName(String.valueOf(source.getStoreState()));
                    }
                    if(source.getState()!=null){
                    Map<Integer,String> StateMap=new HashMap<>();
                        StateMap.put(1,"上架");
                        StateMap.put(2,"下架");
                    String label=  StateMap.get(source.getState());
                    result.setStateName(label);
                    }
                    result.setState(source.getState());
        return result;
    }

}

